package sea.plot;

import java.util.ArrayList;
//import javax.swing.DefaultListModel;
//import javax.swing.ListModel;
import sea.util.PublicParam;
import sea.util.SimHyAHelper;
import sea.util.WinHelper;
import simhya.script.Symbol;


/**
 *
 * This class builds the layout of simulation type of Plot2D interface
 * 
 * @author  Zhirun Ding
 * 
 * Created on 05/07/2012
 * 
 */

public class PlotSimulationTypeForm extends javax.swing.JDialog {
    
    /** Creates new form PlotSimulationTypeForm */
    public PlotSimulationTypeForm(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        trajectoryButtonGroup = new javax.swing.ButtonGroup();
        statTypeButtonGroup = new javax.swing.ButtonGroup();
        typeButtonGroup = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        selectallButton = new javax.swing.JButton();
        deselectButton = new javax.swing.JButton();
        trajectoryRadioButton = new javax.swing.JRadioButton();
        statisticsRadioButton = new javax.swing.JRadioButton();
        trajectoryPanel = new javax.swing.JPanel();
        trajectoryLabel = new javax.swing.JLabel();
        singleRadioButton = new javax.swing.JRadioButton();
        allRadioButton = new javax.swing.JRadioButton();
        rangeRadioButton = new javax.swing.JRadioButton();
        listRadioButton = new javax.swing.JRadioButton();
        singleText = new javax.swing.JTextField();
        fromLabel = new javax.swing.JLabel();
        fromText = new javax.swing.JTextField();
        toLabel = new javax.swing.JLabel();
        toText = new javax.swing.JTextField();
        listText = new javax.swing.JTextField();
        statisticsPanel = new javax.swing.JPanel();
        stattypeLabel = new javax.swing.JLabel();
        averageRadioButton = new javax.swing.JRadioButton();
        varianceRadioButton = new javax.swing.JRadioButton();
        stddevRadioButton = new javax.swing.JRadioButton();
        stderrRadioButton = new javax.swing.JRadioButton();
        cvRadioButton = new javax.swing.JRadioButton();
        fanoRadioButton = new javax.swing.JRadioButton();
        skewRadioButton = new javax.swing.JRadioButton();
        kurtosisRadioButton = new javax.swing.JRadioButton();
        backButton = new javax.swing.JButton();
        confirmButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        simulationvarsList = new javax.swing.JList();
        helpButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sea.SimHyAGui.class).getContext().getResourceMap(PlotSimulationTypeForm.class);
        setTitle(resourceMap.getString("PlotSimulationTypeForm.title")); // NOI18N
        setName("PlotSimulationTypeForm"); // NOI18N
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        selectallButton.setText(resourceMap.getString("selectallButton.text")); // NOI18N
        selectallButton.setName("selectallButton"); // NOI18N
        selectallButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selectallButtonActionPerformed(evt);
            }
        });

        deselectButton.setText(resourceMap.getString("deselectButton.text")); // NOI18N
        deselectButton.setName("deselectButton"); // NOI18N
        deselectButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deselectButtonActionPerformed(evt);
            }
        });

        typeButtonGroup.add(trajectoryRadioButton);
        trajectoryRadioButton.setSelected(true);
        trajectoryRadioButton.setLabel(resourceMap.getString("trajectoryRadioButton.label")); // NOI18N
        trajectoryRadioButton.setName("trajectoryRadioButton"); // NOI18N
        trajectoryRadioButton.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                trajectoryRadioButtonStateChanged(evt);
            }
        });

        typeButtonGroup.add(statisticsRadioButton);
        statisticsRadioButton.setText(resourceMap.getString("statisticsRadioButton.text")); // NOI18N
        statisticsRadioButton.setName("statisticsRadioButton"); // NOI18N
        statisticsRadioButton.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                statisticsRadioButtonStateChanged(evt);
            }
        });

        trajectoryPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        trajectoryPanel.setName("trajectoryPanel"); // NOI18N

        trajectoryLabel.setText(resourceMap.getString("trajectoryLabel.text")); // NOI18N
        trajectoryLabel.setName("trajectoryLabel"); // NOI18N

        trajectoryButtonGroup.add(singleRadioButton);
        singleRadioButton.setSelected(true);
        singleRadioButton.setText(resourceMap.getString("singleRadioButton.text")); // NOI18N
        singleRadioButton.setName("singleRadioButton"); // NOI18N
        singleRadioButton.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                singleRadioButtonItemStateChanged(evt);
            }
        });

        trajectoryButtonGroup.add(allRadioButton);
        allRadioButton.setText(resourceMap.getString("allRadioButton.text")); // NOI18N
        allRadioButton.setName("allRadioButton"); // NOI18N
        allRadioButton.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                allRadioButtonItemStateChanged(evt);
            }
        });

        trajectoryButtonGroup.add(rangeRadioButton);
        rangeRadioButton.setText(resourceMap.getString("rangeRadioButton.text")); // NOI18N
        rangeRadioButton.setName("rangeRadioButton"); // NOI18N
        rangeRadioButton.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                rangeRadioButtonItemStateChanged(evt);
            }
        });

        trajectoryButtonGroup.add(listRadioButton);
        listRadioButton.setText(resourceMap.getString("listRadioButton.text")); // NOI18N
        listRadioButton.setName("listRadioButton"); // NOI18N
        listRadioButton.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                listRadioButtonItemStateChanged(evt);
            }
        });

        singleText.setText(resourceMap.getString("singleText.text")); // NOI18N
        singleText.setName("singleText"); // NOI18N

        fromLabel.setText(resourceMap.getString("fromLabel.text")); // NOI18N
        fromLabel.setName("fromLabel"); // NOI18N

        fromText.setText(resourceMap.getString("fromText.text")); // NOI18N
        fromText.setEnabled(false);
        fromText.setName("fromText"); // NOI18N

        toLabel.setText(resourceMap.getString("toLabel.text")); // NOI18N
        toLabel.setName("toLabel"); // NOI18N

        toText.setText(resourceMap.getString("toText.text")); // NOI18N
        toText.setEnabled(false);
        toText.setName("toText"); // NOI18N

        listText.setText(resourceMap.getString("listText.text")); // NOI18N
        listText.setEnabled(false);
        listText.setName("listText"); // NOI18N

        javax.swing.GroupLayout trajectoryPanelLayout = new javax.swing.GroupLayout(trajectoryPanel);
        trajectoryPanel.setLayout(trajectoryPanelLayout);
        trajectoryPanelLayout.setHorizontalGroup(
            trajectoryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(trajectoryPanelLayout.createSequentialGroup()
                .addGroup(trajectoryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(trajectoryPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(trajectoryLabel))
                    .addGroup(trajectoryPanelLayout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addGroup(trajectoryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(allRadioButton)
                            .addGroup(trajectoryPanelLayout.createSequentialGroup()
                                .addComponent(listRadioButton)
                                .addGap(18, 18, 18)
                                .addComponent(listText))
                            .addGroup(trajectoryPanelLayout.createSequentialGroup()
                                .addGroup(trajectoryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, trajectoryPanelLayout.createSequentialGroup()
                                        .addComponent(singleRadioButton)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(singleText))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, trajectoryPanelLayout.createSequentialGroup()
                                        .addComponent(rangeRadioButton)
                                        .addGap(18, 18, 18)
                                        .addComponent(fromLabel)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(fromText, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(toLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(toText, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(31, Short.MAX_VALUE))
        );
        trajectoryPanelLayout.setVerticalGroup(
            trajectoryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(trajectoryPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(trajectoryLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(trajectoryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(singleRadioButton)
                    .addComponent(singleText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(allRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(trajectoryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rangeRadioButton)
                    .addComponent(fromLabel)
                    .addComponent(fromText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(toLabel)
                    .addComponent(toText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(trajectoryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(listRadioButton)
                    .addComponent(listText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        statisticsPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        statisticsPanel.setName("statisticsPanel"); // NOI18N

        stattypeLabel.setText(resourceMap.getString("stattypeLabel.text")); // NOI18N
        stattypeLabel.setEnabled(false);
        stattypeLabel.setName("stattypeLabel"); // NOI18N

        statTypeButtonGroup.add(averageRadioButton);
        averageRadioButton.setSelected(true);
        averageRadioButton.setText(resourceMap.getString("averageRadioButton.text")); // NOI18N
        averageRadioButton.setEnabled(false);
        averageRadioButton.setName("averageRadioButton"); // NOI18N

        statTypeButtonGroup.add(varianceRadioButton);
        varianceRadioButton.setText(resourceMap.getString("varianceRadioButton.text")); // NOI18N
        varianceRadioButton.setEnabled(false);
        varianceRadioButton.setName("varianceRadioButton"); // NOI18N

        statTypeButtonGroup.add(stddevRadioButton);
        stddevRadioButton.setText(resourceMap.getString("stddevRadioButton.text")); // NOI18N
        stddevRadioButton.setEnabled(false);
        stddevRadioButton.setName("stddevRadioButton"); // NOI18N

        statTypeButtonGroup.add(stderrRadioButton);
        stderrRadioButton.setText(resourceMap.getString("stderrRadioButton.text")); // NOI18N
        stderrRadioButton.setEnabled(false);
        stderrRadioButton.setName("stderrRadioButton"); // NOI18N

        statTypeButtonGroup.add(cvRadioButton);
        cvRadioButton.setText(resourceMap.getString("cvRadioButton.text")); // NOI18N
        cvRadioButton.setEnabled(false);
        cvRadioButton.setName("cvRadioButton"); // NOI18N

        statTypeButtonGroup.add(fanoRadioButton);
        fanoRadioButton.setText(resourceMap.getString("fanoRadioButton.text")); // NOI18N
        fanoRadioButton.setEnabled(false);
        fanoRadioButton.setName("fanoRadioButton"); // NOI18N

        statTypeButtonGroup.add(skewRadioButton);
        skewRadioButton.setText(resourceMap.getString("skewRadioButton.text")); // NOI18N
        skewRadioButton.setEnabled(false);
        skewRadioButton.setName("skewRadioButton"); // NOI18N

        statTypeButtonGroup.add(kurtosisRadioButton);
        kurtosisRadioButton.setText(resourceMap.getString("kurtosisRadioButton.text")); // NOI18N
        kurtosisRadioButton.setEnabled(false);
        kurtosisRadioButton.setName("kurtosisRadioButton"); // NOI18N

        javax.swing.GroupLayout statisticsPanelLayout = new javax.swing.GroupLayout(statisticsPanel);
        statisticsPanel.setLayout(statisticsPanelLayout);
        statisticsPanelLayout.setHorizontalGroup(
            statisticsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statisticsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(statisticsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(stattypeLabel)
                    .addGroup(statisticsPanelLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(statisticsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(averageRadioButton)
                            .addComponent(stddevRadioButton)
                            .addComponent(cvRadioButton)
                            .addComponent(skewRadioButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(statisticsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(kurtosisRadioButton)
                            .addComponent(fanoRadioButton)
                            .addComponent(stderrRadioButton)
                            .addComponent(varianceRadioButton))))
                .addContainerGap(11, Short.MAX_VALUE))
        );
        statisticsPanelLayout.setVerticalGroup(
            statisticsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statisticsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(statisticsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(statisticsPanelLayout.createSequentialGroup()
                        .addComponent(varianceRadioButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(stderrRadioButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(fanoRadioButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(kurtosisRadioButton))
                    .addGroup(statisticsPanelLayout.createSequentialGroup()
                        .addComponent(stattypeLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(averageRadioButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(stddevRadioButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cvRadioButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(skewRadioButton)))
                .addContainerGap(21, Short.MAX_VALUE))
        );

        backButton.setText(resourceMap.getString("backButton.text")); // NOI18N
        backButton.setName("backButton"); // NOI18N
        backButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backButtonActionPerformed(evt);
            }
        });

        confirmButton.setText(resourceMap.getString("confirmButton.text")); // NOI18N
        confirmButton.setName("confirmButton"); // NOI18N
        confirmButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                confirmButtonActionPerformed(evt);
            }
        });

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        simulationvarsList.setName("simulationvarsList"); // NOI18N
        jScrollPane1.setViewportView(simulationvarsList);

        helpButton.setText(resourceMap.getString("helpButton.text")); // NOI18N
        helpButton.setName("helpButton"); // NOI18N
        helpButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(deselectButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(selectallButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(statisticsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(trajectoryPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(144, 144, 144)
                        .addComponent(backButton, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 73, Short.MAX_VALUE)
                        .addComponent(confirmButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(helpButton)))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 212, Short.MAX_VALUE)
                .addComponent(trajectoryRadioButton)
                .addGap(31, 31, 31)
                .addComponent(statisticsRadioButton)
                .addGap(39, 39, 39))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(trajectoryRadioButton)
                        .addComponent(statisticsRadioButton)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(95, 95, 95)
                                .addComponent(selectallButton)
                                .addGap(55, 55, 55)
                                .addComponent(deselectButton))
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(trajectoryPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(statisticsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(confirmButton)
                            .addComponent(backButton)
                            .addComponent(helpButton))
                        .addGap(18, 18, 18))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 381, Short.MAX_VALUE)
                        .addContainerGap())))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backButtonActionPerformed
        this.setVisible(false);
        
        if (PublicParam.PreviousForm != null) {
            PublicParam.PreviousForm.setVisible(true);
        }        
    }//GEN-LAST:event_backButtonActionPerformed

    void enableTrajectoryOrStatTypeRadioButton() {
        //trajectory radiobox
        trajectoryLabel.setEnabled(trajectoryRadioButton.isSelected());
        singleRadioButton.setEnabled(trajectoryRadioButton.isSelected());
        singleText.setEnabled(trajectoryRadioButton.isSelected() && singleRadioButton.isSelected());
        allRadioButton.setEnabled(trajectoryRadioButton.isSelected());
        rangeRadioButton.setEnabled(trajectoryRadioButton.isSelected());
        fromLabel.setEnabled(trajectoryRadioButton.isSelected() && rangeRadioButton.isSelected());
        fromText.setEnabled(trajectoryRadioButton.isSelected() && rangeRadioButton.isSelected());
        toLabel.setEnabled(trajectoryRadioButton.isSelected() && rangeRadioButton.isSelected());
        toText.setEnabled(trajectoryRadioButton.isSelected() && rangeRadioButton.isSelected());
        listRadioButton.setEnabled(trajectoryRadioButton.isSelected());
        listText.setEnabled(trajectoryRadioButton.isSelected() && listRadioButton.isSelected());
        
        //stat type radiobox
        stattypeLabel.setEnabled(statisticsRadioButton.isSelected());
        averageRadioButton.setEnabled(statisticsRadioButton.isSelected());
        varianceRadioButton.setEnabled(statisticsRadioButton.isSelected());
        stddevRadioButton.setEnabled(statisticsRadioButton.isSelected());
        stderrRadioButton.setEnabled(statisticsRadioButton.isSelected());
        cvRadioButton.setEnabled(statisticsRadioButton.isSelected());
        fanoRadioButton.setEnabled(statisticsRadioButton.isSelected());
        skewRadioButton.setEnabled(statisticsRadioButton.isSelected());
        kurtosisRadioButton.setEnabled(statisticsRadioButton.isSelected());
    }
    
    private void trajectoryRadioButtonStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_trajectoryRadioButtonStateChanged
        //boolean isSelected = false;
        //if (trajectoryRadioButton.isSelected()) isSelected = true;
        //if (!statisticsRadioButton.isSelected() && !trajectoryRadioButton.isSelected()) return;
        enableTrajectoryOrStatTypeRadioButton();
    }//GEN-LAST:event_trajectoryRadioButtonStateChanged

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
        if (PublicParam.PreviousForm != null) {
            PublicParam.PreviousForm.setVisible(false);
        }
        
        //get data variable
        String datavar = ((PlotForm)PublicParam.PlotForm).getCurrentDataVariable();
        if (lastDataVariable.equals(datavar)) return;//no change
        lastDataVariable = datavar;
        
        //init vars list        
        ArrayList<Symbol> vars = PublicParam.SimHyACommand.getVariables(datavar);
        WinHelper.initListbox(simulationvarsList, vars);
        //remove item of "time"
        WinHelper.removeFromListbox(simulationvarsList, "time");
        //select all
        WinHelper.setListSelectall(simulationvarsList, "time");
        
        //for ODE trajectories, there should be no statistics option available
        //(check if the data has statistics with method trajectoryVariableContainsStatistics)
        statisticsRadioButton.setEnabled(PublicParam.SimHyACommand.trajectoryVariableContainsStatistics(datavar));
        
        //for ODE data (and all simulations containing a single trajectory ---
        //use new interface method to check this:
        //getNumberOfRunsInTrajectoryVariable ) the trajectory box has to be
        //disabled, as there is only one trajectory to plot.        
        trajectoryRadioButton.setEnabled(PublicParam.SimHyACommand.getNumberOfRunsInTrajectoryVariable(datavar) > 1);
        if (!trajectoryRadioButton.isEnabled()) {
            //trajectory
            trajectoryLabel.setEnabled(false);
            singleRadioButton.setEnabled(false);
            singleText.setEnabled(false);
            allRadioButton.setEnabled(false);
            rangeRadioButton.setEnabled(false);
            fromLabel.setEnabled(false);
            fromText.setEnabled(false);
            toLabel.setEnabled(false);
            toText.setEnabled(false);
            listRadioButton.setEnabled(false);
            listText.setEnabled(false);
        }
    }//GEN-LAST:event_formComponentShown
    
    
    private void selectallButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectallButtonActionPerformed
        WinHelper.setListSelectall(simulationvarsList, "");
    }//GEN-LAST:event_selectallButtonActionPerformed

    private void deselectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deselectButtonActionPerformed
        int[] selectedIndexes = new int[] {-1};
        simulationvarsList.setSelectedIndices(selectedIndexes);    
    }//GEN-LAST:event_deselectButtonActionPerformed

    private void confirmButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmButtonActionPerformed
        //generate plot command expression
        toPlotCommand();        
        //execute command
        this.setVisible(false);
        SimHyAHelper.executeCommand();        
        //close the form
        this.dispose();        
        //clear all form of plot
        WinHelper.closeFormAfterCommand();
    }//GEN-LAST:event_confirmButtonActionPerformed

    private void statisticsRadioButtonStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_statisticsRadioButtonStateChanged
        enableTrajectoryOrStatTypeRadioButton();
    }//GEN-LAST:event_statisticsRadioButtonStateChanged

    private void helpButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpButtonActionPerformed
        WinHelper.showHelp("plot/plot(timetrace)");
    }//GEN-LAST:event_helpButtonActionPerformed

    private void singleRadioButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_singleRadioButtonItemStateChanged
        singleText.setEnabled(singleRadioButton.isSelected());
        fromLabel.setEnabled(!singleRadioButton.isSelected());
        fromText.setEnabled(!singleRadioButton.isSelected());
        toLabel.setEnabled(!singleRadioButton.isSelected());
        toText.setEnabled(!singleRadioButton.isSelected());
        listText.setEnabled(!singleRadioButton.isSelected());
    }//GEN-LAST:event_singleRadioButtonItemStateChanged

    private void allRadioButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_allRadioButtonItemStateChanged
        singleText.setEnabled(!allRadioButton.isSelected());
        fromLabel.setEnabled(!allRadioButton.isSelected());
        fromText.setEnabled(!allRadioButton.isSelected());
        toLabel.setEnabled(!allRadioButton.isSelected());
        toText.setEnabled(!allRadioButton.isSelected());
        listText.setEnabled(!allRadioButton.isSelected());
    }//GEN-LAST:event_allRadioButtonItemStateChanged

    private void rangeRadioButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_rangeRadioButtonItemStateChanged
        singleText.setEnabled(!rangeRadioButton.isSelected());
        fromLabel.setEnabled(rangeRadioButton.isSelected());
        fromText.setEnabled(rangeRadioButton.isSelected());
        toLabel.setEnabled(rangeRadioButton.isSelected());
        toText.setEnabled(rangeRadioButton.isSelected());
        listText.setEnabled(!rangeRadioButton.isSelected());
    }//GEN-LAST:event_rangeRadioButtonItemStateChanged

    private void listRadioButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_listRadioButtonItemStateChanged
        singleText.setEnabled(!listRadioButton.isSelected());
        fromLabel.setEnabled(!listRadioButton.isSelected());
        fromText.setEnabled(!listRadioButton.isSelected());
        toLabel.setEnabled(!listRadioButton.isSelected());
        toText.setEnabled(!listRadioButton.isSelected());
        listText.setEnabled(listRadioButton.isSelected());
    }//GEN-LAST:event_listRadioButtonItemStateChanged
    
    void toPlotCommand() {
        String s = "";
        
        //trajectoryRadioButton judeg
        if (trajectoryRadioButton.isEnabled() && trajectoryRadioButton.isSelected()) {
            if (singleRadioButton.isSelected() && singleText.getText().length() > 0) {
                s += ",trajectory=" + singleText.getText();
            } else if (allRadioButton.isSelected()) {                
                s += ",trajectory=all";
            } else if (rangeRadioButton.isSelected()  && fromText.getText().length() > 0  && toText.getText().length() > 0) {                
                s += ",trajectory=" + fromText.getText() + ":" + toText.getText();
            } else if (listRadioButton.isSelected() && listText.getText().length() > 0) {
                s += ",trajectory=[" + listText.getText() + "]";
            }
        }
        
        //statisticsRadioButton judeg
        if (statisticsRadioButton.isEnabled() && statisticsRadioButton.isSelected()) {
            if (averageRadioButton.isSelected()) {
                s += ",stat=average";
            } else if (varianceRadioButton.isSelected()) {
                s += ",stat=variance";
            } else if (stddevRadioButton.isSelected()) {
                s += ",stat=stddev";
            } else if (stderrRadioButton.isSelected()) {
                s += ",stat=stderr";
            } else if (cvRadioButton.isSelected()) {
                s += ",stat=cv";
            } else if (fanoRadioButton.isSelected()) {
                s += ",stat=fano";
            } else if (skewRadioButton.isSelected()) {
                s += ",stat=skew";
            } else if (kurtosisRadioButton.isSelected()) {
                s += ",stat=kurtosis";
            }
        }
        
        //vars
        if (simulationvarsList.getSelectedValues().length > 0) {
            s += ",vars=[";
            for (int i = 0; i < simulationvarsList.getSelectedValues().length; i++) {
                if (i > 0) s += ",";
                s += simulationvarsList.getSelectedValues()[i].toString();
            }
            s += "]";
        }
        
        PublicParam.SimHyACommandExpression += s + ")";
        PublicParam.CommandTypeName = "Plot";
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                PlotSimulationTypeForm dialog = new PlotSimulationTypeForm(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton allRadioButton;
    private javax.swing.JRadioButton averageRadioButton;
    private javax.swing.JButton backButton;
    private javax.swing.JButton confirmButton;
    private javax.swing.JRadioButton cvRadioButton;
    private javax.swing.JButton deselectButton;
    private javax.swing.JRadioButton fanoRadioButton;
    private javax.swing.JLabel fromLabel;
    private javax.swing.JTextField fromText;
    private javax.swing.JButton helpButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JRadioButton kurtosisRadioButton;
    private javax.swing.JRadioButton listRadioButton;
    private javax.swing.JTextField listText;
    private javax.swing.JRadioButton rangeRadioButton;
    private javax.swing.JButton selectallButton;
    private javax.swing.JList simulationvarsList;
    private javax.swing.JRadioButton singleRadioButton;
    private javax.swing.JTextField singleText;
    private javax.swing.JRadioButton skewRadioButton;
    private javax.swing.ButtonGroup statTypeButtonGroup;
    private javax.swing.JPanel statisticsPanel;
    private javax.swing.JRadioButton statisticsRadioButton;
    private javax.swing.JLabel stattypeLabel;
    private javax.swing.JRadioButton stddevRadioButton;
    private javax.swing.JRadioButton stderrRadioButton;
    private javax.swing.JLabel toLabel;
    private javax.swing.JTextField toText;
    private javax.swing.ButtonGroup trajectoryButtonGroup;
    private javax.swing.JLabel trajectoryLabel;
    private javax.swing.JPanel trajectoryPanel;
    private javax.swing.JRadioButton trajectoryRadioButton;
    private javax.swing.ButtonGroup typeButtonGroup;
    private javax.swing.JRadioButton varianceRadioButton;
    // End of variables declaration//GEN-END:variables
    private String lastDataVariable = "";
}
